import java.util.*;

public class Solution1239 {

    public int maxLength(List<String> arr) {
        int ans=0;
        int[][] map=new int[20][20];
        List<String> list=new ArrayList<>();
        for (String s : arr) {
            int flag=1;
            for (int k=0;k<26;k++){
                if (s.indexOf((char)('a'+k))!=s.lastIndexOf((char)('a'+k))){
                    flag=0;
                    break;
                }
            }
            if (flag==1){
               list.add(s);
            }
        }
        arr=list;
        for (int i=0;i<arr.size();i++){
            map[i][i]=0;
            for (int j=i+1;j<arr.size();j++){
                String s=arr.get(i).concat(arr.get(j));
                int flag=1;
                for (int k=0;k<26;k++){
                    if (s.indexOf((char)('a'+k))!=s.lastIndexOf((char)('a'+k))){
                        flag=0;
                        break;
                    }
                }
                map[i][j]=flag;
                map[j][i]=flag;
            }
        }
        Queue<Integer> queue=new LinkedList<>();
        queue.offer(0);
        int[] visited=new int[1<<arr.size()];
        visited[0]=1;
        while (!queue.isEmpty()){
            int t=queue.poll();
            int count=0;
            for (int i=0;i<arr.size();i++){
                if ((t&(1<<i))!=0){
                    count=count+arr.get(i).length();
                }
            }
            ans=Math.max(ans,count);
            for (int i=0;i<arr.size();i++){
                int flag=1;
                for (int j=0;j<arr.size();j++){
                    if (map[i][j]==0 && (t&(1<<j))!=0){
                        flag=0;
                        break;
                    }
                }
                if (flag==1 && visited[t|(1<<i)]==0){
                    queue.offer(t|(1<<i));
                    visited[t|(1<<i)]=1;
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("un");
        list.add("iq");
        list.add("ue");
        list.add("aa");
        System.out.println(new Solution1239().maxLength(list));
    }
}
